<template>
    <div>
        <el-row :gutter="20">
            <el-col :span="8">
                <el-card shadow="hover" class="mgb20" style="height:526px;">
                    <div class="user-info">
                        <img src="../assets/img/img.jpg" class="user-avator" alt/>
                        <div class="user-info-cont">
                            <div class="user-info-name">{{ name }}</div>
                            <div>{{ role }}</div>
                        </div>
                    </div>
                    <!-- <div class="user-info-list">
                        <div class="user-info-list_text">上次登录时间：</div>
                        {{ $moment(tableData.login_info.create_time * 1000).format('YYYY-MM-DD mm:hh:ss') }}
                    </div>
                    <div class="user-info-list">
                        <div class="user-info-list_text">上次登录IP：</div>
                        {{ tableData.login_info.ip }}
                    </div> -->
                </el-card>
            </el-col>
            <el-col :span="16">
                <!-- <el-row :gutter="20" class="mgb20">
                    <el-col :span="24">
                        <el-card shadow="hover" :body-style="{padding: '0px'}">
                            <div class="grid-content grid-con-1">
                                <i class="el-icon-lx-people grid-con-icon"></i>
                                <div class="grid-cont-right">
                                    <div class="grid-num">{{ tableData.count_user }}</div>
                                    <div>用户总人数</div>
                                </div>
                            </div>
                        </el-card>
                    </el-col>
                </el-row> -->
                <!-- <el-card shadow="hover" style="height:403px;">
                    <div slot="header" class="clearfix">
                        <span>待发货</span>
                        <el-button style="float: right; padding: 3px 0" type="text" @click='goto'>更多</el-button>
                    </div>
                    <el-table
                            :data="tableData.order_list.list"
                            border
                            class="table"
                            ref="multipleTable"
                            element-loading-text="拼命加载中"
                            element-loading-spinner="el-icon-loading"
                            element-loading-background="rgba(0, 0, 0, 0.8)"
                            v-loading="loading"
                            header-cell-class-name="table-header">
                        <el-table-column prop="id" label="序号" align="center"></el-table-column>
                        <el-table-column prop="order_num" label="订单号" align="center"></el-table-column>
                        <el-table-column prop="name" label="用户" align="center"></el-table-column>
                        <el-table-column prop="telephone" label="联系方式" align="center"></el-table-column>
                        <el-table-column prop="create_time" label="创建时间" align="center"></el-table-column>
                    </el-table>
                </el-card> -->
            </el-col>
        </el-row>
        <el-row :gutter="20">
            <el-col :span="24">
                <el-card shadow="hover">
                    <schart ref="bar" class="schart" canvasId="bar" :options="options"></schart>
                </el-card>
            </el-col>
<!--            <el-col :span="12">-->
<!--                <el-card shadow="hover">-->
<!--                    <schart ref="line" class="schart" canvasId="line" :options="options2"></schart>-->
<!--                </el-card>-->
<!--            </el-col>-->
        </el-row>
    </div>
</template>

<script>
import {
    Loading
} from 'element-ui';
import Schart from 'vue-schart';
import AxiosPost from '../api/index'

export default {
    name: 'Dashboard',
    data() {
        return {
            loading: true,
            tableData: {
                login_info: {}, //登录信息
                proportion: {},  //总信息
                order_list: [], //待发货订单
            },
            name: localStorage.getItem('ms_username'),
            options: {
                type: 'bar',
                title: {
                    text: '最近一周用户新增趋势图'
                },
                xRorate: 50,
                labels: [],
                datasets: [{
                    label: '新增人数',
                    data: []
                }]
            },
            options2: {
                type: 'line',
                title: {
                    text: '最近一周用户购买趋势图'
                },
                labels: [],
                yEqual: 10,
                datasets: [{
                    label: '消费金额',
                    data: []
                }]
            }
        };
    },
    components: {
        Schart
    },
    computed: {
        role() {
            return this.name === 'admin' ? '超级管理员' : '普通用户';
        }
    },
    created() {
        this.getData();
    },
    methods: {
        async getData() {
            // this.loading = true
            // let info = await AxiosPost('/admin/login/adminindex', this.query)
            // this.loading = false
            // if (info.code !== 10000) {
            //     this.$message.error(info.message)
            //     return false
            // }

            // this.tableData = info.data
            // this.options.labels = this.tableData.weeks_time;
            // this.options2.labels = this.tableData.weeks_time;
            // let arr = [], arr2 = []
            // this.tableData.order_list.list.forEach(item => {
            //     item.create_time = this.$moment(item.create_time * 1000).format('YYYY-MM-DD HH:mm:ss')
            // })
            // this.tableData.user_up.forEach(item => {
            //     arr.push(Number(item))
            // })
            // this.options.datasets[0].data = arr
            // this.tableData.weeks_money.forEach(item => {
            //     arr2.push(Number(item))
            // })
            // this.options2.datasets[0].data = arr2
        },

        goto() {
            this.$router.push({
                path: '/OrderList',
                query: {
                    status: 1
                }
            });
        }

    }
};
</script>


<style scoped>
.el-row {
    margin-bottom: 20px;
}

.grid-content {
    display: flex;
    align-items: center;
    height: 100px;
}

.grid-cont-right {
    flex: 1;
    text-align: center;
    font-size: 14px;
    color: #999;
}

.grid-num {
    font-size: 30px;
    font-weight: bold;
}

.grid-con-icon {
    font-size: 50px;
    width: 100px;
    height: 100px;
    text-align: center;
    line-height: 100px;
    color: #fff;
}

.grid-con-1 .grid-con-icon {
    background: rgb(45, 140, 240);
}

.grid-con-1 .grid-num {
    color: rgb(45, 140, 240);
}

.grid-con-2 .grid-con-icon {
    background: rgb(100, 213, 114);
}

.grid-con-2 .grid-num {
    color: rgb(45, 140, 240);
}

.grid-con-3 .grid-con-icon {
    background: rgb(242, 94, 67);
}

.grid-con-3 .grid-num {
    color: rgb(242, 94, 67);
}

.user-info {
    display: flex;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 2px solid #ccc;
    margin-bottom: 10px;
}

.user-avator {
    width: 120px;
    height: 120px;
    border-radius: 50%;
}

.user-info-cont {
    padding-left: 50px;
    flex: 1;
    font-size: 14px;
    color: #999;
}

.user-info-cont div:first-child {
    font-size: 30px;
    color: #222;
}

.user-info-list {
    font-size: 14px;
    color: #999;
    line-height: 25px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info-list span {
    margin-left: 70px;
}

.mgb20 {
    margin-bottom: 20px;
}

.todo-item {
    font-size: 14px;
}

.todo-item-del {
    text-decoration: line-through;
    color: #999;
}

.schart {
    width: 100%;
    height: 300px;
}
</style>
